import request from '@/utils/request.js'

// 发布公告
export function createNotices(data) {
  return request({
    url: '/notices/create',
    method: 'post',
    data
  })
}

// 查询
export function searchNotices(options) {
  const { label, value, subscriber, page_num, page_size } = options
  return request({
    url: '/notices/search',
    method: 'post',
    data: {
      [label]: value,
      subscriber:String(subscriber),
      page_num,
      page_size
    }
  })
}

// 删除
export function deleteNotices(id) {
  return request({
    url: `/notices/${id}`,
    method: 'delete'
  })
}

// 根据接收者获取最新一条公告
export function getNewNotices(subscriber) {
  return request({
    url: `/notices/new/${subscriber}`,
  })
}

// 获取用户的公告（消息模块中的查看公告）
export function getUserNotices(options) {
  const { label, value, subscriber, page_num, page_size } = options
  return request({
    url: '/notices/mynotices',
    method: 'post',
    data: {
      [label]: value,
      subscriber:String(subscriber),
      page_num,
      page_size
    }
  })
}
